//
//  Theme.swift
//  SitPosition
//
//  Created by apple on 2018/12/31.
//  Copyright © 2018 apple. All rights reserved.
//

import Foundation
import UIKit


/**
 * 兼容Web格式的颜色值
 */
extension UIColor {
    convenience init(r: Int, g: Int, b: Int) {
        self.init(red: CGFloat(r)/255.0,
                  green: CGFloat(g)/255.0,
                  blue: CGFloat(b)/255.0,
                  alpha: 1.0)
    }
    
    convenience init(hexString: String, alpha: CGFloat) {
        assert(!hexString.isEmpty)
        
        let cs: CharacterSet = CharacterSet.whitespacesAndNewlines
        let hexString_: String = hexString.trimmingCharacters(in: cs)
        let scanner: Scanner = Scanner(string: hexString_)
        
        if (hexString_.hasPrefix("#")) {
            scanner.scanLocation = 1
        }
        
        var color:UInt32 = 0
        scanner.scanHexInt32(&color)
        
        let mask = 0x000000FF
        let r = Int(color >> 16) & mask
        let g = Int(color >> 8) & mask
        let b = Int(color) & mask
        
        let red   = CGFloat(r) / 255.0
        let green = CGFloat(g) / 255.0
        let blue  = CGFloat(b) / 255.0
        
        self.init(red: red, green: green, blue: blue, alpha: alpha)
    }
}

struct Theme {
    
    // 字体
    struct Font {
        static let boldFontName: String = "PingFangSC-Semibold"
        static let mediumFontName: String = "PingFangSC-Medium"
        static let regularFontName: String = "PingFangSC-Regular"
        static let dinotMediumFontName: String = "DINOT-Medium"
        
        static func boldFont(ofSize size: CGFloat) -> UIFont {
            return UIFont(name: boldFontName, size: size) ??
                UIFont.boldSystemFont(ofSize: size)
        }
        
        static func mediumFont(ofSize size: CGFloat) -> UIFont {
            return UIFont(name: mediumFontName, size: size) ??
            UIFont.boldSystemFont(ofSize:size)
        }
        
        static func regularFont(ofSize size: CGFloat) -> UIFont {
            return UIFont(name: regularFontName, size: size) ??
            UIFont.systemFont(ofSize:size)
        }
        
        static func dinotMediumFont(ofSize size: CGFloat) -> UIFont {
            return UIFont(name: dinotMediumFontName, size: size) ??
                UIFont.systemFont(ofSize:size)
        }
    }
    
    // 颜色
    struct Color {
        static let warningColor: UIColor = UIColor(hexString: "#FF293D", alpha: 1.0)
        static let primaryBackgroundColor: UIColor = UIColor(hexString: "#F5F7F9", alpha: 1.0)
        
        static let primaryBlueColor: UIColor = UIColor(hexString: "#5387F5", alpha: 1.0)
        static let primaryBlueSeperatorColor: UIColor = UIColor(hexString: "#5387F5", alpha: 1.0)
        static let primaryDarkSeperatorColor: UIColor = UIColor(hexString: "#F2F2F2", alpha: 1.0)
        
        static let primaryLightTextColor: UIColor = UIColor.white
        static let primaryDarkTextColor: UIColor = UIColor(hexString: "#333333", alpha: 1.0)
        static let primaryDark2TextColor: UIColor = UIColor(hexString: "#111111", alpha: 1.0)
        static let primaryBlueTextColor: UIColor = UIColor(hexString: "#8BA8FB", alpha: 1.0)
        static let primaryDarkGrayTextColor: UIColor = UIColor(hexString: "#7D8091", alpha: 1.0)
        static let placeholderTextColor: UIColor = UIColor(hexString: "#5387F5", alpha: 1.0)
        
        static let deepDarkTextColor: UIColor = UIColor(hexString: "#131313", alpha: 1.0)
        static let deepgrayTextColor: UIColor = UIColor(hexString: "#979797", alpha: 1.0)
        static let lighgrayTextColor: UIColor = UIColor(hexString: "#B1B5C1", alpha: 1.0)
        
        static let seperatorColor: UIColor = UIColor(hexString: "#E6E8F0", alpha: 1.0)
        static let priceColor: UIColor = UIColor(hexString: "#8CA8FB", alpha: 1.0)
    }
    
    // Toast
    struct Toast {
        static let normalDuration: TimeInterval = 1
        static let mediumDuration: TimeInterval = 2
        static let longDuration: TimeInterval = 3
    }
}
